package com.jltx.zeus.arch

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.lifecycleScope
import kotlinx.android.synthetic.main.activity_main2.*
import kotlinx.coroutines.launch
import kotlin.coroutines.Continuation
import kotlin.coroutines.ContinuationInterceptor
import kotlin.coroutines.CoroutineContext

class MainActivity2 : AppCompatActivity() {
    private val TAG = "MainActivity2"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
        btn.setOnClickListener {
            startActivity(
                Intent(
                    this,
                    MainActivity::class.java
                )
            )
        }

        val interceptor = object : ContinuationInterceptor {
            override val key: CoroutineContext.Key<*>
                get() = ContinuationInterceptor

            override fun <T> interceptContinuation(continuation: Continuation<T>): Continuation<T> {
                return object : Continuation<T> {
                    override val context: CoroutineContext
                        get() = continuation.context

                    override fun resumeWith(result: Result<T>) {
                        Log.d(TAG, "MyContinuation $result")
                        continuation.resumeWith(result)
                    }

                }
            }

        }
        lifecycleScope.launch(interceptor) {

        }
    }
}